package com.zhaorui.enablescheduling;

import com.zhaorui.entity.GzTfJh;
import com.zhaorui.mapper.GzMfMoMapper;
import com.zhaorui.mapper.GzTfJhMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 静态执行
 */
@Configuration //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling // 2.开启定时任务
@Slf4j
public class SimpleScheduleConfig6 {
    @Autowired
    private GzMfMoMapper gzMfMoMapper;

    //3.添加定时任务
    @Scheduled(cron = "0 */1 * * * ?")
//    @Scheduled(cron = "*/35 * * * * ?")

    /**
     * 自动更新mo派工单
     */
    private void configureTasks() {
        System.err.println("执行Tf_jh--Gz_Tf_jh定时任务: " + LocalDateTime.now().toLocalTime());
        //查询需要更新的订单
        Integer count = gzMfMoMapper.queryMfMo();
        if (count == 0) {
            log.info("暂无数据");
            return;
        }
        //依次更新
        for (int i = 0; i < count-1; i++) {
            gzMfMoMapper.updateMfMo();
        }
        log.info("更新GZ_MF_MO,{},数据", count);
    }
}